<%@ page contentType="text/html; charset=iso-8859-1" language="java"%>
<%@ taglib uri="/WEB-INF/lib/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/lib/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/lib/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/lib/c.tld" prefix="c"%>

<script>
function submitForm(opr){
	document.modelRecordForm.opr.value = opr;
	document.modelRecordForm.submit();
//	alert("teste");
}

function insertBrand(){
	document.modelRecordForm.opr.value = 'insertBrand';
	if (confirm('<bean:message key="vehicle.prompt.confirmInsertBrand" />')){
		document.modelRecordForm.submit();
	}
}

function insertModel(){
	document.modelRecordForm.opr.value = 'insertModel';
	if (confirm('<bean:message key="vehicle.prompt.confirmInsertModel" />')){
		document.modelRecordForm.submit();
	}
}
/*
function editBrand(id){
	document.modelRecordForm.opr.value = 'editBrand';
	document.modelRecordForm.id.value = id;
	if (confirm('<bean:message key="vehicle.prompt.confirmEditBrand" />')){
		document.modelRecordForm.submit();
	}
}

function editModel(id){
	document.modelRecordForm.opr.value = 'editModel';
	document.modelRecordForm.id.value = id;	
	if (confirm('<bean:message key="vehicle.prompt.confirmEditModel" />')){
		document.modelRecordForm.submit();
	}
}*/

function removeBrand(id){
	document.modelRecordForm.opr.value = 'removeBrand';
	document.modelRecordForm.id.value = id;	
	if (confirm('<bean:message key="vehicle.prompt.confirmRemoveBrand" />')){
		document.modelRecordForm.submit();
	}
}


function removeModel(id){
	document.modelRecordForm.opr.value = 'removeModel';
	document.modelRecordForm.id.value = id;	
	if (confirm('<bean:message key="vehicle.prompt.confirmRemoveModel" />')){
		document.modelRecordForm.submit();
	}
}

function clearBrandFields(){
	document.modelRecordForm.opr.value = 'clearBrandFields';
	document.modelRecordForm.submit();
}

function clearModelFields(){
	document.modelRecordForm.opr.value = 'clearModelFields';
	document.modelRecordForm.submit();
}


</script>

<html:form action="/modelRecord">
	<html:hidden property="opr" />
	<html:hidden property="id" />

	<table border="0" width="100%">
		<tr>
			<td>


			<!-------------------------------------------------------
			----------------Cadastro de Marca -----------------------
			------------------------------------------------------ -->
			
			<logic:present name="messageErrorEx">
				<h4 style="font: red;"><bean:write name="messageErrorEx"/></h4>
			</logic:present>
			
			<table border="0">
				<tr>
					<td align="center">
						<h3><bean:message key="vehicle.option.recordBrand" /></h3>
					</td>
				</tr>
				<tr>
					<td width="40%"><bean:message key="vehicle.label.insertBrand" />:<br />
					<html:text property="brand" size="50" /> </td>
				</tr>
				<tr>
		 			<td>
						<table width="100%">
							<tr>
								<td width="30%">
								</td>
								<td width="20%">
									<a href="javascript:insertBrand()"><bean:message key="vehicle.label.record" /></a>
								</td>
								<td width="20%">
									<a href="javascript:clearBrandFields()"><bean:message key="vehicle.label.clear" /></a>
								</td>
								<td width="30%">
								</td>
							</tr>
						</table>
					 </td>
				</tr>
				
				<tr>
					<td align="center">
					<table style="border: 1px solid #969696;" cellpadding="0" cellspacing="0">
						<tr style="background-color: #969696; height: 20px; font-weight: bold;">
							<td>&nbsp;</td>
								<td width="10%"><bean:message key="vehicle.label.id" /></td>
								<td ><bean:message key="vehicle.labels.brand" /></td>
								<td width="5%"></td>
								<td>&nbsp;</td>
						</tr>
						<c:if test="${brandsCollection != null}">
						<logic:iterate id="brand" name="brandsCollection" >

						<c:choose>
							<c:when test="${color == '#f3f2f2'}">
								<c:set var="color" value="#e7e6e6" scope="page"/>
							</c:when>
							<c:otherwise>
								<c:set var="color" value="#f3f2f2" scope="page"/>
							</c:otherwise>
						</c:choose>

						<tr style="background-color: <c:out value="${color}" /> ; height: 15px;">
							<td>&nbsp;</td>
							<td><bean:write name="brand" property="id"/></td>
							<td><bean:write name="brand" property="brand"/></td>
							<td><a href="javascript:removeBrand('<bean:write name="brand" property="id"/>');"><img src="resources/excluir.gif" border="0" alt="Excluir Marca"/></a></td>
							<td>&nbsp;</td>
						</tr>
	
						</logic:iterate>
						</c:if>
						<c:if test="${brandsCollection == null}">
							<td colspan="6">
								<bean:message key="vehicle.label.nobrand" />
							</td>						
						</c:if>
					</table>
					</td>
				
				</tr>
			</table>
			
			</td>
		</tr>


			<!-------------------------------------------------------
			----------------Cadastro de Modelo -----------------------
			------------------------------------------------------ -->
		
		<tr>
			<td>
			
			<c:if test="${brandsCollection != null}">
			
			<table border="0" style="margin-top: 10px;">
				<tr>
					<td align="center">
						<h3><bean:message key="vehicle.option.recordModel" /><h3>
					</td>
				</tr>
				<tr>
					<td width="40%"><bean:message key="vehicle.label.selectBrand" />:<br />
					<html:select property="selectedBrand" onchange="submitForm('changeModel')">>
						<html:options collection="brandsCollection" property="id" labelProperty="brand" />
					</html:select></td>
				</tr>

				<tr>
					<td width="40%"><bean:message key="vehicle.label.insertModel" />:<br />
					<html:text property="model" size="50" /> </td>
				</tr>

		<tr>
		 <td>
			<table width="100%">
				<tr>
					<td width="30%">
					</td>
					<td width="20%">
						<a href="javascript:insertModel()"><bean:message key="vehicle.label.record" /></a>
					</td>
					<td width="20%">
						<a href="javascript:clearModelFields()"><bean:message key="vehicle.label.clear" /></a>
					</td>
					<td width="30%">
					</td>
				</tr>
			</table>
		 </td>
		</tr>


				<tr>
					<td align="center">
					<table style="border: 1px solid #969696;" cellpadding="0" cellspacing="0">
						<tr style="background-color: #969696; height: 20px; font-weight: bold;">
							<td>&nbsp;</td>
								<td width="10%"><bean:message key="vehicle.label.id" /></td>
								<td ><bean:message key="vehicle.labels.model" /></td>
								<td width="5%"></td>
								<td>&nbsp;</td>
						</tr>
	
						<c:if test="${modelsCollection != null}">
						<logic:iterate id="model" name="modelsCollection" >
			
						<c:choose>
							<c:when test="${color == '#f3f2f2'}">
								<c:set var="color" value="#e7e6e6" scope="page"/>
							</c:when>
							<c:otherwise>
								<c:set var="color" value="#f3f2f2" scope="page"/>
							</c:otherwise>
						</c:choose>			
			
						<tr style="background-color: <c:out value="${color}" /> ; height: 15px;">
							<td>&nbsp;</td>
							<td><bean:write name="model" property="id"/></td>
							<td><bean:write name="model" property="model"/></td>							
							<td><a href="javascript:removeModel('<bean:write name="model" property="id"/>');"><img src="resources/excluir.gif" border="0" alt="Excluir Marca"/></a></td>
							<td>&nbsp;</td>
						</tr>
	
						</logic:iterate>
						</c:if>
						<c:if test="${modelsCollection == null}">
						<tr>
							<td colspan="6">
								<bean:message key="vehicle.label.nomodel" />
							</td>
						</tr>
						</c:if>
						</table>
					</td>
				</tr>
			</table>
			
			</c:if>
			
			</td>
		</tr>
	</table>
	
<br/>

</html:form>
